<?php

use App\Models\Product;
use Faker\Generator as Faker;

$factory->define(App\Models\OrderItem::class, function (Faker $faker) {
    // 从数据库随机取出一条商品
    $product = Product::query()->where('on_sale', true)->inRandomOrder()->first();

    // 从该商品中取出一条SKU
    $sku = $product->skus()->inRandomOrder()->first();
    return [
        'amount' => rand(1, 5),
        'price' => $sku->price,
        'rating' => null,
        'review' => null,
        'reviewed_at' => null,
        'product_id' => $product->id,
        'product_sku_id' => $sku->id,
    ];
});
